package com.aisile.student.controller;

import com.aisile.model.student.dtos.StudentListDto;
import com.aisile.model.student.pojos.Student;
import com.aisile.model.base.vos.R;
import com.aisile.student.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther:yry
 * @Date:2024/6/19 0019
 * @VERSON:1.0
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("/list")
    public R findAllByPage(@RequestBody StudentListDto dto){
        return studentService.findAllByPage(dto);
    }

    // 根据tid 查询关联学生
    @GetMapping("/num/{id}")
    public R findStudentNumByTid(@PathVariable("id") Integer id){
        return studentService.findStudentNumByTid(id);
    }


    // 都是feign使用的接口  对我们来讲  与前端交互的接口 需要统一返回给是  与后端交互的接口（feing） 怎么方便怎么来
    @PostMapping("/saves/{teacherId}")
    public R saveStudents(@PathVariable("teacherId") Integer teacherId,@RequestBody List<Student> list){
        studentService.saveStudents(teacherId,list);
        return R.ok();
    }

    @DeleteMapping("/del/{id}")
    public R deleteStudentsbyTid(@PathVariable("id") Integer id){
        studentService.deleteStudentsbyTid(id);
        return R.ok();
    }

    @GetMapping("/getOne")
    public List<Student> getStudentByTid(@RequestParam("id") Integer id){
        return  studentService.getStudentByTid(id);
    }




}
